package com.maikang.exammall.configuration;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
import com.fasterxml.jackson.databind.module.SimpleModule;

import java.io.IOException;

public class StringTrimModule extends SimpleModule {
	/**
	 * 全局反序列化去除字符串前后空格
	 */
	private static final long serialVersionUID = 1L;
 
	public StringTrimModule() {
		addDeserializer(String.class, new StdScalarDeserializer<String>(String.class) {
			
			private static final long serialVersionUID = 1L;
 
			@Override
			public String deserialize(JsonParser p, DeserializationContext ctxt)
					throws IOException, JsonProcessingException {
				String value = p.getValueAsString();
				return value.trim();
			}
		});
	}
}
